package com.handle.system.web.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.handle.common.core.utils.ContextHolderUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author zq
 * @date 2020/06/16
 * @description: description
 * @version: 1.0.0
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("createStaff", ContextHolderUtils.getCurrentUser().getUserId(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("update_time",LocalDateTime.now(),metaObject);
        this.setFieldValByName("updateStaff", ContextHolderUtils.getCurrentUser().getUserId(),metaObject);
    }
}

